import { Breadcrumb } from 'antd';
import { useLocation } from 'react-router-dom';
import { HOME_URL } from '@/config/config';
import { connect } from 'react-redux';

const BreadcrumbNav = (props: any) => {
	const { pathname } = useLocation();
	const { themeConfig } = props.global;
	const breadcrumbList = props.breadcrumb.breadcrumbList[pathname] || [];
	return (
		<>
			{!themeConfig.breadcrumb && (
				<Breadcrumb>
					<Breadcrumb.Item href={`#${HOME_URL}`}>启动页</Breadcrumb.Item>
					{breadcrumbList.map(({ path, label }: any) => {
						return (
							<Breadcrumb.Item key={path} href={path == pathname ? undefined : `#${path}`}>
								{label}
							</Breadcrumb.Item>
						);
					})}
				</Breadcrumb>
			)}
		</>
	);
};

const mapStateToProps = (state: any) => state;
export default connect(mapStateToProps)(BreadcrumbNav);
